package com.xyf.sys.service.impl;

import com.xyf.sys.domain.OrderAddress;
import com.xyf.sys.mapper.OrderAddressMapper;
import com.xyf.sys.service.IOrderAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class OrderAddressServiceImpl implements IOrderAddressService {

    @Autowired
    private OrderAddressMapper orderAddressMapper;

    @Override
    public void save(OrderAddress orderAddress) {
        orderAddressMapper.insert(orderAddress);
    }

    @Override
    public List<OrderAddress> getOrderAddressList(String productId) {
        return orderAddressMapper.selectByOrderProductId(productId);
    }

    @Override
    public List<OrderAddress> getAddressList(String orderId) {
        return orderAddressMapper.selectByOrderId(orderId);
    }

    @Override
    public void batchUpdate(List<OrderAddress> addressList) {
        if (CollectionUtils.isEmpty(addressList)){
            return;
        }
        for (OrderAddress address : addressList) {
            address.setLastUpdateTime(new Date());
            orderAddressMapper.updateByPrimaryKeySelective(address);
        }
    }
}
